package com.aqie.easy.matrix;

/**
 * 566 重塑矩阵
 * 双指针
 * todo
 */
public class MatrixReshape {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        int R = nums.length;
        int C = nums[0].length;
        if (R * C != r * c) return nums;
        int row = 0;
        int col = 0;
        int[][] res = new int[r][c];

        for (int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                if (col >= C){
                    row ++;
                    col = 0;
                }
                res[i][j] = nums[row][col];
                col++;
            }
        }

        return res;
    }
}
